package com.lry.thompson;

import java.util.HashSet;
import java.util.Set;

public class Nfa {


    public static final int EPSILON = -1; //边对应的是ε
    public static final int CCL = -2; //边对应的是字符集
    public static final int EMPTY = -3; //该节点没有出去的边
    public static final int ASCII_COUNT = 127;
    public static int NFA_STATE_NUM = 1;


    public Nfa next;
    public Nfa next2;//只有当前nfa节点含有两条EPSILON边 next2才有效
    public int stateNum;//节点编号
    public int edge;//边转换对应的输入, 单个字符，ccl...

    public Set<Byte> inputSet = new HashSet<>();//边如果是ccl需要inputSet

    public Nfa(){
        this.stateNum = NFA_STATE_NUM++;
        this.edge = EPSILON;
    }

    public boolean isEndNfa(){
        return null==next && null==next2;
    }

    public void setComplement() {
        Set<Byte> newSet = new HashSet<>();
        for(byte i=0;i<ASCII_COUNT;i++){
            if(!inputSet.contains(i)){
                newSet.add(i);
            }
        }
        inputSet = newSet;
    }
}
